//
//  WCCoreDataStore.h
//  WC
//
//  Created by 杨鑫 on 15/5/6.
//  Copyright (c) 2015年 智康. All rights reserved.
//

#import <Foundation/Foundation.h>
//
#import "NSManagedObject+SetValueWithDictionary.h"
//
#import "Account.h"
#import "AccountStat.h"
#import "AccountService.h"
#import "HistoryPatient.h"
#import "Patient.h"
#import "PatientScheme.h"
#import "Comment.h"
#import "Order.h"
#import "OrderComment.h"
//
#import "AccountServiceEntity.h"
#import "AccountServiceConfigEntity.h"

@interface WCCoreDataStore : NSObject



@property (strong, nonatomic) NSManagedObjectContext *context;
#pragma mark - Create

+ (instancetype)shareStore;

#pragma mark - Account

/**
 *  用户登录后创建用户实体
 *  @param data NSDictionary
 *  @return Account
 */
- (Account *)createAccount:(NSDictionary *)data;

/**
 *  更新用户评分
 *  @param stat NSDictionary
 */
- (AccountStat *)updateAccountStat:(NSDictionary *)stat;

/**
 *  更新护士服务设置
 *  @param service NSDictionary
 */
- (AccountService *)updateAccountService:(NSDictionary *)service;

/**
 *  获得保存的用户信息
 *  @return Account
 */
- (Account *)getAccount;

/**
 *  获得账户评分
 *  @return AccountStat
 */
- (AccountStat *)getAccountStat;

/**
 *  获得用户服务配置
 *  @return AccountService
 */
- (AccountServiceEntity *)getAccountService;

#pragma mark - Patient

/**
 *  添加过往病人
 *  @param data NSArray
 *  @return NSArray
 */
- (NSArray *)createHistoryPatients:(NSArray *)data save:(BOOL)save;

/**
 *  获得第一页的过往患者
 *  @return NSArray
 */
- (NSArray *)getHistoryPatients;

/**
 *  当前患者
 *  @param data NSArray
 *  @return NSArray
 */
- (NSArray *)createPatients:(NSArray *)data;
- (Patient *)createPatient:(NSDictionary *)data save:(BOOL)save;

/**
 *  当前缓存的患者
 *  @return NSArray
 */
- (NSArray *)getPatients;

/**
 *  更新患者
 *  @param patient
 *  @param data  NSDictionary
 */
- (void)updateIdPatient:(id)patient withData:(NSDictionary *)data;

/**
 *  更新或创建病人护理的方案
 *  @param data     NSArray
 *  @param recordId NSString
 */
- (NSArray *)createPatientSchemes:(NSArray *)data withRecord:(NSString *)recordId;

/**
 *  创建一个空的，与上下文无关的实体
 *  @return PatientScheme
 */
- (PatientScheme *)createPatientScheme;

/**
 *  查找病人护理记录的方案
 *  @param recordId NSString
 */
- (NSArray *)getPatientSchemes:(NSString *)recordId;

#pragma mark - Comments

/**
 *  添加评论数组
 *  @param data NSArray
 *  @param save BOOL
 *
 *  @return NSArray
 */
- (NSArray *)createComments:(NSArray *)data save:(BOOL)save;

/**
 *  获取第一页的评论
 *  @return NSArray
 */
- (NSArray *)getComments;

#pragma mark - Orders

- (NSArray *)createOrders:(NSArray *)data withCategory:(int)category save:(BOOL)save;
- (NSArray *)getOrdersByCategory:(int)category;
- (void)updateOrder:(Order *)order withData:(NSDictionary *)data;

#pragma mark - OrderComment

- (OrderComment *)createOrderComment:(NSDictionary *)data save:(BOOL)save;
- (OrderComment *)getOrderCommentById:(NSString *)commentId;

#pragma mark - Others

/**
 *  保存数据到文件
 *  @return BOOL
 */
- (BOOL)saveData;

/**
 *  清空所有数据
 */
- (void)removeAllData;

/**
 *  插入数据
 *  @param list NSArray
 *  @param is BOOL 是否删除（查询到数据）
 *
 *  @return NSArray
 */
- (NSArray *)cwqInsertWithEntity:(NSString *)name array:(NSArray *)list overWrite:(BOOL)is predicate:(NSPredicate *)predicate sort:(NSArray *)sort;

/**
 *  取出数据
 *  @param sorts 排序
 *  @param predicate 查询条件
 *
 *  @return NSArray
 */
- (NSArray *)cwqFindWithEntity:(NSString *)name sort:(NSArray *)sorts predicate:(NSPredicate *)predicate pageSize:(NSInteger)pageSize currentCount:(NSInteger)currentCount;
@end
